/*
	PlAr is Platform Arena: a 2D multiplayer shooting game
	Copyright (c) 2010, Antonio Ragagnin <spocchio@gmail.com>
    All rights reserved.

    This file is licensed under the New BSD License.
*/

package plar.core;

/**
 * This action is used to manage collisions with other object:
 * - call a special function for each collision
 * - call a special function if there was accepted collisions (if the previous functions returned TRUE)
 * - can get a BREAK of "gap" from each collision.
 *
 * this last feature is used by the ElementGadget to reactivate an Ammo packet only
 * after a gap of time. this Action was written for ElementGadget so there are
 * pre-made method for them Element. but you can override them with no problems,
 * as in ElementBullet;
 *
 * This class is extended by ElementBullet to manage the collision overriding
 * timeOut(), collision(), touching () functions.
 *
 * @author Antonio Ragagnin
 */
public class ActionTouch extends ActionTimer {




    /*
     * @ct activate the timer mode
     */
    public ActionTouch(float t1) {
        super("",t1,0,true);
    }

    public Object force(Object parameters) {
        if(flag) timeOut();
        return null;
    }


    public void run() {
        super.run();
        if(flag)
        {
            check1();
        } else check2();
    }

    public void check1()
    {
        check();
    }
    public void check2()
    {   check();
    }
    public void check()
    {
        boolean collision = false;
        //repeat=false;
        if (me.collisionList != null) {

            for (Element e : me.collisionList) {
                //Common.info(1,"e: "+me+ " collided con "+e);
                collision |= collision(me, e);

            }
            if (collision) {
                touched();
            }
        }
    }

    public boolean collision(Element me, Element e) {
        active=true;
        return false;
    }

    public void timeOut() {

    }

    public void touched() {};

}
